home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload Trio 2
/
Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO
/
dir31
/
mt32ds10.zip
/
MT32DISP.BAS
next >
Wrap
BASIC Source File
|
1992-11-16
|
9KB
|
178 lines
'╔══════════════════════════════════════════════════════════════════════════════╗
'║ PROGRAM: MT32DISP.EXE Version 1.00 LENGTH: 132 ║
'║ ║
'║ This program sends MIDI exclusive message data to the Roland MPU-401. ║
'║ The exclusive message contains information specific for the Roland MT-32. ║
'║ The message is Data Set (DT1, 12h) that passes the user's text to the ║
'║ MT-32 display's address area. The format for the exclusive message is: ║
'║ ║
'║ Exclusive Manufacturer's Device Model Command Data .......... EOX ║
'║ Status ID ID ID ID ║
'║ F0h 41h 10h 16h 12h 20h 00h 00h ... F7h ║
'║ (Roland) (#17) (MT-32) (DT1) (LCD address) ║
'║ ║
'║ TITLE: Text To MT-32 LCD Display Program ║
'║ COMPILER: Microsoft QuickBASIC 4.5 ║
'║ DEVELOPED BY: John J. Hanney, jr. ║
'║ DATE: 23 December 1989. ║
'║ MODIFIED: 16 November 1992 Version 1.00 (QB 4.5) JJHjr. ║
'║ ║
'║ (C)Copyright 1989, 1992 John J. Hanney, jr. ║
'║ All rights reserved. ║
'╚══════════════════════════════════════════════════════════════════════════════╝
REM set up variables, etc ...
DEFINT M 'Make al "M" variables integers.
L$ = CHR$(10) 'L$=Line feed.
MCMDPORT = &H331 'Midi command port.
MSTATPORT = &H331 'Midi status port.
MDATAPORT = &H330 'Midi data port.
MDSR = &H80 'Data Send Register.
MDRR = &H40 'Data Read Register.
MACK = &HFE 'Acknowledgement.
MRETSTAT = 0 'Return status from midi subroutines..
MWORK1 = 0 'Work variable #1 for midi subroutines.
MWORK2 = 0 'Work variable #2 for midi subroutines.
MTRIES = 0 'Counter for midi subroutines.
REM Variables that may require change ...
MAXTRIES = 5120 'Time out value, for compiled run.
' Can use 512 for interpretive run.
MTDEV = &H10 'MT-32 device number = 17. Remember, 17 is "really" 16 (10h).
' Change if device other than 17.
'════════════════════════════════════════════════════════════════════════════════
'┌─────────────────────┐
'│ Display title once. │
'└─────────────────────┘
PRINT "MT32DISP: Text To MT-32 LCD Display Program"
PRINT TAB(11); "Version 1.00 - Freeware"
PRINT TAB(11); "By: John J. Hanney, jr."; L$
'════════════════════════════════════════════════════════════════════════════════
BEGIN10:
'┌────────────────┐
'│ Reset MPU-401. │
'└────────────────┘
GOSUB MIDIRESET: IF MRETSTAT <> 0 THEN GOTO STEPERR10
BEGIN20:
'┌──────────────────────────────────────────────────────────────────────┐
'│ Line input text into Z$. (Use line input so quotes can be entered.) │
'└──────────────────────────────────────────────────────────────────────┘
Z$ = ""
LINE INPUT "Key in 20 characters and press ENTER (nothing to quit): ", Z$
IF Z$ = "" THEN GOTO STEPEND
'────────────────────────────────────────────────────────────────────────────────
FIXDATA:
'┌─────────────────────────────────────────┐
'│ Fix text so only ASCII 32-127 are used. │
'└─────────────────────────────────────────┘
Z$ = LEFT$(Z$, 20): Y = &H20 'Y=Inital Checksum
FOR Z = 1 TO LEN(Z$) 'Won't do this if LEN(Z$)=0
REM ----------- Make character a space if not ASCII 32-127.
IF MID$(Z$, Z, 1) < " " OR MID$(Z$, Z, 1) > CHR$(127) THEN MID$(Z$, Z, 1) = " "
REM ----------- Add character to checksum.
Y = Y + ASC(MID$(Z$, Z, 1))
NEXT Z
'┌───────────────────────────────────┐
'│ Prefix Z$ with exclusive message. │
'└───────────────────────────────────┘
Z$ = CHR$(&HF0) + CHR$(&H41) + CHR$(MTDEV) + CHR$(&H16) + CHR$(&H12) + CHR$(&H20) + CHR$(0) + CHR$(0) + Z$
'┌───────────────────────┐
'│ Add checksum and EOX. │
'└───────────────────────┘
Z$ = Z$ + CHR$(&H80 - (Y AND &H7F)) + CHR$(&HF7)
SENDDATA10:
'┌───────────────────────────┐
'│ Put MPU-401 in UART mode. │
'└───────────────────────────┘
MWORK1 = &H3F '3Fh="UART" Midi Command.
Z = 0: MRETSTAT = 1 'Init counter and Midi return status.
DO WHILE Z < 2 AND MRETSTAT <> 0
GOSUB PUTCMD: Z = Z + 1 'Send UART Midi Command.
LOOP
IF MRETSTAT <> 0 THEN GOTO STEPERR10
SENDDATA20:
'┌─────────────────────────────────────────────────┐
'│ Send each byte of exclusive message to MPU-401. │
'└─────────────────────────────────────────────────┘
FOR Z = 1 TO LEN(Z$)
MWORK1 = ASC(MID$(Z$, Z, 1)) 'Place byte in MWORK1.
GOSUB PUTDATA 'Send data, ignore MRETSTAT
NEXT Z
GOTO BEGIN10
'════════════════════════════════════════════════════════════════════════════════
STEPERR10:
PRINT "MT32DISP Error: MPU-401 not responding ...": BEEP
GOTO STEPEND
STEPEND:
PRINT L$; "MT32DISP: Complete ...": END
' ╔═════════════╗
'═╣ SUBROUTINES ╠════════════════════════════════════════════════════════════════
' ╚═════════════╝
REM --- MIDI Subroutines ---
'┌───────────────────────────────────────────────────────────────┐
'│ Send A Command To The Midi Command Port │
'│ MRETSTAT = 0 ...... Successful. │
'│ MRETSTAT = 1 ...... MPU-IPC not in receive state. │
'│ MRETSTAT = 2 ...... MPU-IPC did not clear DSR bit. │
'│ MRETSTAT = 3 ...... ACK not received. │
'└───────────────────────────────────────────────────────────────┘
PUTCMD: MRETSTAT = 0: MTRIES = MAXTRIES
PUTCMDB: MTRIES = MTRIES - 1: IF MTRIES = 0 THEN MRETSTAT = 1: GOTO PUTCMDZ
IF (INP(MSTATPORT) AND MDRR) <> 0 THEN MWORK2 = INP(MDATAPORT): GOTO PUTCMDB
OUT MSTATPORT, MWORK1: MTRIES = MAXTRIES
PUTCMDC: MTRIES = MTRIES - 1: IF MTRIES = 0 THEN MRETSTAT = 2: GOTO PUTCMDZ
IF (INP(MSTATPORT) AND MDSR) <> 0 THEN GOTO PUTCMDC
IF INP(MDATAPORT) <> MACK THEN MRETSTAT = 3
PUTCMDZ: RETURN
'┌───────────────────────────────────────────────────────────────┐
'│ Get Data From Midi Data Port │
'│ MRETSTAT = 0 ...... Successful. │
'│ MRETSTAT = 2 ...... MPU-IPC did not clear DSR bit. │
'└───────────────────────────────────────────────────────────────┘
GETDATA: MRETSTAT = 0: MTRIES = MAXTRIES
GETDATAB: MTRIES = MTRIES - 1: IF MTRIES = 0 THEN MRETSTAT = 2: GOTO GETDATAZ
IF (INP(MSTATPORT) AND MDSR) <> 0 THEN GOTO GETDATAB
MWORK1 = INP(MDATAPORT)
GETDATAZ: RETURN
'┌───────────────────────────────────────────────────────────────┐
'│ Send Data Thru Midi Data Port │
'│ MRETSTAT = 0 ...... Successful. │
'│ MRETSTAT = 1 ...... MPU-IPC not in receive state. │
'└───────────────────────────────────────────────────────────────┘
PUTDATA: MRETSTAT = 0: MTRIES = MAXTRIES
PUTDATAB: MTRIES = MTRIES - 1: IF MTRIES = 0 THEN MRETSTAT = 1: GOTO GETDATAZ
IF (INP(MSTATPORT) AND MDRR) <> 0 THEN MWORK2 = INP(MDATAPORT): GOTO PUTDATAB
OUT MDATAPORT, MWORK1
PUTDATAZ: RETURN
'────────────────────────────────────────────────────────────────────────────────
REM --- Other Subroutines ---
'┌───────────────────────────────────────────────────────────────┐
'│ Reset MPU-401 ... │
'└───────────────────────────────────────────────────────────────┘
MIDIRESET:
MWORK1 = &HFF 'FFh=Reset Midi Command.
Z = 0: MRETSTAT = 1 'Init counter and Midi return status.
DO WHILE Z < 2 AND MRETSTAT <> 0
GOSUB PUTCMD: Z = Z + 1 'Send Reset Midi Command.
LOOP
RETURN